#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN DATA ABSTRACTION LAYER version 1

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Using directives
using System;
using Thn.Collections;
#endregion

namespace Thn.Data
{
    /// <summary>
    /// Strongly typed collection of Conditions.
    /// </summary>
    public class ConditionCollection : CollectionBase
    {
        #region Constructor
        /// <summary>
        /// Default constructor.
        /// </summary>
        public ConditionCollection()
            : base()
        {
        }
        #endregion

        #region Indexer
        /// <summary>
        /// Gets or sets the value of the Condition at a specific position in the ConditionCollection.
        /// </summary>
        public Condition this[int index]
        {
            get
            {
                return ((Condition)(this.List[index]));
            }
            set
            {
                this.List[index] = value;
            }
        }
        #endregion

        #region Add
        /// <summary>
        /// Append a Condition entry to this collection.
        /// </summary>
        /// <param name="value">Condition instance.</param>
        /// <returns>The position into which the new element was inserted.</returns>
        public int Add(Condition value)
        {
            return this.List.Add(value);
        }
        #endregion

        #region Contains
        /// <summary>
        /// Determines whether a specified Condition instance is in this collection.
        /// </summary>
        /// <param name="value">Condition instance to search for.</param>
        /// <returns>True if the Condition instance is in the collection; otherwise false.</returns>
        public bool Contains(Condition value)
        {
            return this.List.Contains(value);
        }
        #endregion

        #region Index Of
        /// <summary>
        /// Retrieve the index a specified Condition instance is in this collection.
        /// </summary>
        /// <param name="value">Condition instance to find.</param>
        /// <returns>The zero-based index of the specified Condition instance. If the object is not found, the return value is -1.</returns>
        public int IndexOf(Condition value)
        {
            return this.List.IndexOf(value);
        }
        #endregion

        #region Remove
        /// <summary>
        /// Removes a specified Condition instance from this collection.
        /// </summary>
        /// <param name="value">The Condition instance to remove.</param>
        public void Remove(Condition value)
        {
            this.List.Remove(value);
        }
        #endregion

        #region Get Enumerator
        /// <summary>
        /// Returns an enumerator that can iterate through the Condition instance.
        /// </summary>
        /// <returns>An Condition's enumerator.</returns>
        public new System.Collections.IEnumerator GetEnumerator()
        {
            return new ConditionCollectionEnumerator(this);
        }

        #region Enumerator
        /// <summary>
        /// Strongly typed enumerator of Condition.
        /// </summary>
        public class ConditionCollectionEnumerator : object, System.Collections.IEnumerator
        {
            #region privates
            /// <summary>
            /// Current index
            /// </summary>
            private int mIndex;

            /// <summary>
            /// Current element pointed to.
            /// </summary>
            private Condition mCurrentElement;

            /// <summary>
            /// Collection to enumerate.
            /// </summary>
            private ConditionCollection mCollection;
            #endregion

            #region Constructor
            /// <summary>
            /// Default constructor for enumerator.
            /// </summary>
            /// <param name="collection">Instance of the collection to enumerate.</param>
            internal ConditionCollectionEnumerator(ConditionCollection collection)
            {
                mIndex = -1;
                mCollection = collection;
            }
            #endregion

            #region Current
            /// <summary>
            /// Gets the Condition object in the enumerated ConditionCollection currently indexed by this instance.
            /// </summary>
            public Condition Current
            {
                get
                {
                    if (((mIndex == -1)
                                || (mIndex >= mCollection.Count)))
                    {
                        throw new System.IndexOutOfRangeException("Enumerator not started.");
                    }
                    else
                    {
                        return mCurrentElement;
                    }
                }
            }

            /// <summary>
            /// Gets the current element in the collection.
            /// </summary>
            object System.Collections.IEnumerator.Current
            {
                get
                {
                    if (((mIndex == -1)
                                || (mIndex >= mCollection.Count)))
                    {
                        throw new System.IndexOutOfRangeException("Enumerator not started.");
                    }
                    else
                    {
                        return mCurrentElement;
                    }
                }
            }
            #endregion

            #region Reset
            /// <summary>
            /// Reset the cursor, so it points to the beginning of the enumerator.
            /// </summary>
            public void Reset()
            {
                mIndex = -1;
                mCurrentElement = null;
            }
            #endregion

            #region MoveNext
            /// <summary>
            /// Advances the enumerator to the next queue of the enumeration, if one is currently available.
            /// </summary>
            /// <returns>true, if the enumerator was succesfully advanced to the next queue; false, if the enumerator has reached the end of the enumeration.</returns>
            public bool MoveNext()
            {
                if ((mIndex
                            < (mCollection.Count - 1)))
                {
                    mIndex = (mIndex + 1);
                    mCurrentElement = this.mCollection[mIndex];
                    return true;
                }
                mIndex = mCollection.Count;
                return false;
            }
            #endregion
        }
        #endregion
        #endregion

        #region Insert
        /// <summary>
        /// Insert a Condition instance into this collection at a specified index.
        /// </summary>
        /// <param name="index">Zero-based index.</param>
        /// <param name="value">The Condition instance to insert.</param>
        public void Insert(int index, Condition value)
        {
            this.List.Insert(index, value);
        }
        #endregion
    }
}
